let a = "9007199254740991";
let b = "1234567899999999999";

function add(a, b) {
    //取两个数字的最大长度
    const maxLength = Math.max(a.length, b.length);
    //用0去补齐长度
    a = a.padStart(maxLength, 0); //"0009007199254740991"
    b = b.padStart(maxLength, 0); //"1234567899999999999"

    //定义加法过程中需要用到的变量
    let t = 0;
    let carray = 0; //"进位"
    let sum = "";

    for (let i = maxLength - 1; i >= 0; i--) {
        t = parseInt(a[i]) + parseInt(b[i]) + carray;
        carray = Math.floor(t / 10);
        sum = t % 10 + sum;
    }

    if (carray === 1) {
        sum = "1" + sum;
    }

    return sum;
}

console.log(add('1', '2'));
console.log(add(a, b)); //结果为：1243575099254740990